﻿using SolidPrinciples.OpenClosed;

namespace SolidPrinciples.InterfaceSegregation
{
    /// <summary>
    /// ISP violation:
    /// 
    /// To implement a widget for just showing Sum To Pay that widget is pushed to implement Show(IEnumerable<Product>)
    /// 
    /// </summary>
    public class PointOfSaleTerminalPresenter
    {
        private readonly PointOfSaleTerminal _pointOfSaleTerminal;
        private readonly IPointOfSaleTerminalView _view;

        public PointOfSaleTerminalPresenter(IPointOfSaleTerminalView view)
        {
            _pointOfSaleTerminal = new PointOfSaleTerminal();
            view.NewProductRegisterPressed += ViewOnNewProductRegisterPressed;
            _view = view;
        }

        private void ViewOnNewProductRegisterPressed(object sender, NewProductRegisterPressEventArgs args)
        {
            _pointOfSaleTerminal.Register(product: args.Product, amount: args.Amount);
            _view.Show(_pointOfSaleTerminal.Products);
            _view.ShowSumToPay(_pointOfSaleTerminal.SumToPay);
        }
    }
}